const cloud = require('wx-server-sdk')

//npm   install  request-promise  通过终端下载npm install wx-server-sdk ，
const rp = require('request-promise');

cloud.init()

// 云函数入口函数

exports.main = async (event, context) => {
  const _JSCODE = event.code
  console.log(_JSCODE)
  const AccessToken_options = {
    method: 'GET',
    url: 'https://api.weixin.qq.com/sns/jscode2session',

    qs: {

      appid: 'wxd64cb14fdd9c5283',  //你的小程序appid；

      secret: '0e447623a124aed41d1c3ecbaad8a3ce',  //你的秘钥

      grant_type: 'authorization_code',

      js_code: _JSCODE

    },

    json: true



  };


  const resultValue = await rp(AccessToken_options);

  return { resultValue }
}